{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "### Lesson 1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Fundamentals of Risk and Return of a Portfolio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1GoalHeaderImage.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## 1.1  Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A **portfolio** is a basket of tradable assets such as stocks, bonds, commodities etc., which are held by an investor or investors. \n",
    "To keep matters simple  and straight, let us consider an investor who is interested in investing in Dow stocks. Dow or Dow30  or Dow Jones Industrial Average (DJIA) is a stock market index that shows how a selective set of 30 large and publicly owned companies in the United States, have traded over a period of time. The investor is interested in the following Dow30 stocks, 29 in number and whose **ticker** symbols have been shown in parantheses:\n",
    "\n",
    "3M (MMM), American Express (AXP), Apple (AAPL), Boeing (BA), Caterpillar (CAT), Chevron (CVX), Cisco (CSCO), Coca-Cola (KO), Exxon Mobil (XOM), Goldman Sachs (GS), Home Depot (HD), IBM (IBM), Intel (INTC), Johnson & Johnson (JNJ), JPMorgan Chase (JPM), McDonald's (MCD), Merck (MRK), Microsoft (MSFT), Nike (NKE), Pfizer (PFE), Procter & Gamble (PG), Travelers Companies Inc. (TRV), United Health (UNH), United Technologies (UTX), Verizon (VZ), Visa (V), Walmart (WMT), Walgreens Boots Alliance (WBA) and Walt Disney (DIS).\n",
    "\n",
    "The daily historical prices of a few Dow30 stocks for the period April 01, 2019 to April 10, 2019 have been shown in Fig. 1.1, which is a snapshot of the CSV file,  holding the historical dataset.  The historical prices of all stocks traded in any global stock exchange  can be downloaded for free from some  financial websites  or subscribed for,  from stock exchanges or other websites. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Fig1_1.png)\n",
    "<h4 align=\"center\">Fig. 1.1 Historical prices (daily) of a few Dow30 stocks - a snapshot</h4>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2  Rate of Return"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us suppose the investor purchased a stock for a price $P_0$ at time $T_0$ and sold it at time $T_1$ for a price $P_1$. The time period between $T_0$  and $T_1$ is called as the **holding period** and the **rate of return** or the **holding period return** denoted by $R_T$ in the absence of any cash flows such as dividends etc., and expressed as a percentage is given by\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "![](Lesson1Eqn1_1.png)\n",
    "<h5 align=\"right\">..........(1.1)</h5>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For example,  the rate of return of AAPL stock assuming that it was bought on April 02, 2019 and sold on April 03, 2019 is, $ \\left(\\frac{195.35-194.02}{194.02}\\right)X 100 = 0.69\\%$. In other words, the daily return of AAPL is 0.69% for the day concerned.  \n",
    "  \n",
    "The holding period could be any calendar time such as days, weeks, months etc.   \n",
    "  \n",
    "The daily returns of all the Dow stocks listed in Section 1.1 can be computed using a Python code shown in the cell below.The code assumes that a CSV file with all the historical prices of the stocks, a snapshot of which was illustrated in Fig. 1.1 is available. The historical dataset considered for the Dow stocks is DJIA Index: April 11, 2014 to April 11, 2019. The CSV file comprises 1259 rows of data excluding the header and 29 columns excluding the date. The output of the Python code  is the daily returns(%) of the stocks. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['AAPL', 'AXP', 'BA', 'CAT', 'CSCO', 'CVX', 'DIS', 'GS', 'HD', 'IBM', 'INTC', 'JNJ', 'JPM', 'KO', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PFE', 'PG', 'TRV', 'UNH', 'UTX', 'V', 'VZ', 'WBA', 'WMT', 'XOM']\n",
      "(1259, 29)\n",
      "            AAPL         AXP          BA         CAT       CSCO         CVX  \\\n",
      "0      74.230003   84.540001  122.070000  101.449997  22.459999  117.029999   \n",
      "1      74.525711   85.500000  123.250000  102.779999  22.850000  118.699997   \n",
      "2      73.994286   86.040001  124.269997  102.500000  22.889999  120.300003   \n",
      "3      74.144287   87.400002  126.040001  102.930000  23.030001  121.830002   \n",
      "4      74.991432   86.220001  127.919998  102.830002  23.209999  123.680000   \n",
      "...          ...         ...         ...         ...        ...         ...   \n",
      "1254  197.000000  110.959999  391.929993  140.360001  55.209999  126.419998   \n",
      "1255  200.100006  110.699997  374.519989  139.820007  55.490002  126.680000   \n",
      "1256  199.500000  109.849998  369.040009  136.350006  55.180000  125.540001   \n",
      "1257  200.619995  110.160004  364.940002  137.529999  55.820000  125.489998   \n",
      "1258  198.949997  109.849998  370.160004  138.869995  55.599998  125.989998   \n",
      "\n",
      "             DIS          GS          HD         IBM  ...        PFE  \\\n",
      "0      77.010002  152.720001   75.699997  195.190002  ...  29.860001   \n",
      "1      77.620003  154.740005   75.970001  197.770004  ...  29.870001   \n",
      "2      77.660004  154.919998   75.889999  197.020004  ...  29.889999   \n",
      "3      78.949997  157.220001   76.580002  196.399994  ...  30.090000   \n",
      "4      79.989998  157.440002   77.089996  190.009995  ...  30.250000   \n",
      "...          ...         ...         ...         ...  ...        ...   \n",
      "1254  115.000000  202.380005  202.059998  143.279999  ...  42.990002   \n",
      "1255  114.959999  202.539993  203.550003  143.389999  ...  43.139999   \n",
      "1256  116.860001  200.619995  200.899994  142.110001  ...  42.840000   \n",
      "1257  117.160004  202.979996  199.429993  143.020004  ...  42.730000   \n",
      "1258  116.599998  202.830002  201.479996  143.779999  ...  42.270000   \n",
      "\n",
      "              PG         TRV         UNH         UTX           V         VZ  \\\n",
      "0      80.760002   85.300003   78.949997  113.930000   49.157501  47.070000   \n",
      "1      80.809998   85.500000   79.180000  114.940002   50.252499  47.270000   \n",
      "2      80.839996   85.889999   79.510002  115.839996   51.012501  46.919998   \n",
      "3      81.650002   86.779999   78.190002  118.070000   52.340000  47.099998   \n",
      "4      81.760002   86.680000   75.779999  118.570000   51.987499  47.599998   \n",
      "...          ...         ...         ...         ...         ...        ...   \n",
      "1254  103.650002  136.399994  248.779999  133.720001  157.649994  59.090000   \n",
      "1255  104.970001  135.880005  248.750000  133.559998  157.750000  59.130001   \n",
      "1256  104.660004  135.190002  248.789993  132.250000  157.490005  58.400002   \n",
      "1257  104.650002  135.460007  246.029999  131.660004  158.559998  58.610001   \n",
      "1258  104.750000  136.279999  235.419998  132.820007  157.860001  58.560001   \n",
      "\n",
      "            WBA         WMT         XOM  \n",
      "0     64.260002   76.500000   96.720001  \n",
      "1     65.669998   77.379997   97.860001  \n",
      "2     66.010002   76.879997   98.680000  \n",
      "3     66.160004   77.220001   99.940002  \n",
      "4     66.750000   77.660004  100.419998  \n",
      "...         ...         ...         ...  \n",
      "1254  54.689999   98.830002   82.489998  \n",
      "1255  55.060001   99.230003   83.000000  \n",
      "1256  54.500000   98.690002   81.930000  \n",
      "1257  54.509998   99.599998   81.559998  \n",
      "1258  53.439999  100.800003   81.949997  \n",
      "\n",
      "[1259 rows x 29 columns]\n"
     ]
    }
   ],
   "source": [
    "#Python code to compute the daily returns in percentage, of Dow Stocks listed in Sec.1.1\n",
    "#calls function StockReturnsComputing to compute asset returns\n",
    "\n",
    "#dependencies\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "#input stock prices dataset\n",
    "stockFileName = 'DJIA_Apr112014_Apr112019.csv'\n",
    "rows = 1259  #excluding header\n",
    "columns = 29  #excluding date\n",
    "\n",
    "#read stock prices \n",
    "df = pd.read_csv(stockFileName,  nrows= rows)\n",
    "\n",
    "#extract asset labels\n",
    "assetLabels = df.columns[1:columns+1].tolist()\n",
    "print(assetLabels)\n",
    "\n",
    "#extract asset prices data\n",
    "stockPrice = df.iloc[0:, 1:]\n",
    "print(stockPrice.shape)\n",
    "\n",
    "#print stock price\n",
    "print(stockPrice)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Python function **StockReturnsComputing (StockPrice, Rows, Columns)** computes the daily returns of stocks, given the daily stock prices **StockPrice** and its size (**Rows, Columns**)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "#function to compute asset returns \n",
    "def StockReturnsComputing(StockPrice, Rows, Columns):\n",
    "    \n",
    "    import numpy as np\n",
    "    \n",
    "    StockReturn = np.zeros([Rows-1, Columns])\n",
    "    for j in range(Columns):        # j: Assets\n",
    "        for i in range(Rows-1):     # i: Daily Prices\n",
    "            StockReturn[i,j]=((StockPrice[i+1, j]-StockPrice[i,j])/StockPrice[i,j])* 100\n",
    "\n",
    "    return StockReturn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Python code fragment shown in the cell below,  computes the daily returns of the Dow stocks selected by the investor."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Daily returns of selective Dow 30 stocks\n",
      " [[ 0.39836722  1.13555594  0.96665847 ...  2.19420472  1.15032288\n",
      "   1.17866004]\n",
      " [-0.71307606  0.63158012  0.82758377 ...  0.51774632 -0.64616182\n",
      "   0.83793071]\n",
      " [ 0.20271971  1.5806613   1.42432127 ...  0.22724132  0.44225288\n",
      "   1.27685651]\n",
      " ...\n",
      " [-0.29985306 -0.76784013 -1.46320094 ... -1.01707408 -0.54419126\n",
      "  -1.28915663]\n",
      " [ 0.561401    0.28220847 -1.11099255 ...  0.01834495  0.92207517\n",
      "  -0.45160747]\n",
      " [-0.83241852 -0.2814143   1.43037266 ... -1.96294082  1.20482432\n",
      "   0.47817436]]\n"
     ]
    }
   ],
   "source": [
    "#compute daily returns in percentage of the Dow stocks\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "stockPriceArray = np.asarray(stockPrice)\n",
    "[Rows, Cols]=stockPriceArray.shape\n",
    "stockReturns = StockReturnsComputing(stockPriceArray, Rows, Cols)\n",
    "print('Daily returns of selective Dow 30 stocks\\n', stockReturns)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3  Return on Market Index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A **Market Index**  serves to give a fair idea about how the overall  market data or specific segments of the market perform. DJIA index is one of several indices that exist in global markets and attempts to describe market conditions with the help of the 30 companies listed under it.  \n",
    "  \n",
    "Market index data comprises the following details, viz., **Open**, **High**, **Low**, **Close**, **Adjusted Close** and **Volume**, indicating the opening, high, low, closing and  adjusted close of the prices and the volume of trade undertaken for the period, respectively. Of these,  the closing price of the market index is considered to be  important.  \n",
    " \n",
    "A snapshot of the DJIA Index for the period between April 01, 2019 to April 10, 2019 is shown in Fig. 1.2."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Fig1_2.png)\n",
    "\n",
    "<h4 align=\"center\">Fig. 1.2 Market index of DJIA during April 01, 2019 to April 10, 2019 - a snapshot</h4>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The **return on market index** is computed in a way similar to the rate of return of a stock explained by equation (1.1). Thus the daily return of market index is obtained by subtracting the closing price at time T with that at time (T-1) and dividing the difference by the closing price at time (T-1), before expressing it as a percentage. The Adjusted Closing price can also be considered for the computation,  in lieu of Closing price.  \n",
    "The DJIA market index percentage returns for the period April 02, 2019 to April 10, 2019 can be computed as, (-0.30, 0.15 0.64 0.15 -0.32 -0.72 0.03).\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Market indices are useful to investors since it helps  investors to measure the performance of their portfolios against that of the markets. Thus if the daily market index return was 0.15 and that of the portfolio which the investor holds was 0.19 then there is a reason to rejoice,  since the investor was able to beat the market!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.4  Mean and Covariance of Returns "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The mean and covariance of returns play a dominant role in determining the return and risk of a portfolio. The mean returns are denoted by $(\\mu_1, \\mu_2, ...\\mu_N)$ for the N stocks comprising the portfolio. The covariance of returns is a symmetric matrix referred to as the **variance-covariance matrix of returns**  and is denoted by $\\left(\\sigma_{i,j}\\right)$. The diagonal of the matrix $\\left(\\sigma_{i,i}\\right)$ denotes the variance of returns.  The Python code fragment demonstrating the computatation of the mean and covariance of returns is  shown below: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean returns of Dow Stocks:\n",
      " [ 0.09027598  0.02910022  0.09966449  0.0386567   0.0809993   0.01551509\n",
      "  0.03975381  0.03313877  0.08479014 -0.01611022  0.07274221  0.03154811\n",
      "  0.06041058  0.01915697  0.05653419  0.04422144  0.03579986  0.09974359\n",
      "  0.08008644  0.03375828  0.02514231  0.04254659  0.09548076  0.01871582\n",
      "  0.10128134  0.02314321 -0.00168528  0.02946248 -0.0061016 ]\n",
      "Variance-covariance matrix of returns of Dow Stocks:\n",
      "\n",
      "[[2.37512857 0.67159954 0.96196299 1.04226142 0.99890235 0.66413311\n",
      "  0.68002487 0.9540385  0.72630968 0.70945859 1.07333017 0.48572094\n",
      "  0.8251006  0.30601011 0.45823283 0.73218    0.53433977 1.22660419\n",
      "  0.77524223 0.5444771  0.41917661 0.50943202 0.77433417 0.69274799\n",
      "  1.0086701  0.29354661 0.69735896 0.44587945 0.63272823]\n",
      " [0.67159954 1.64817768 0.80008198 0.9502813  0.70010508 0.63080612\n",
      "  0.56872139 1.06463549 0.65826615 0.66251941 0.73789772 0.47196466\n",
      "  1.00101545 0.30743029 0.35037656 0.65268493 0.55568077 0.7945144\n",
      "  0.68112631 0.54156063 0.34473927 0.53506318 0.71830933 0.67723734\n",
      "  0.84700893 0.34247718 0.66688086 0.37953128 0.52158702]\n",
      " [0.96196299 0.80008198 2.28788869 1.31010124 0.88951117 0.81235903\n",
      "  0.71613388 1.06553088 0.7474291  0.77691868 0.96595019 0.56720978\n",
      "  0.97737004 0.38099252 0.47170257 0.87223471 0.57833707 0.92506778\n",
      "  0.8218734  0.53242063 0.41390469 0.62206326 0.74452648 0.93342475\n",
      "  0.92483951 0.42031728 0.67937008 0.50859443 0.72979658]\n",
      " [1.04226142 0.9502813  1.31010124 2.73293774 1.04070962 1.23579738\n",
      "  0.68846207 1.32135157 0.79609702 0.88512353 1.15246617 0.53207219\n",
      "  1.16862013 0.3575928  0.45532119 1.06821468 0.61626811 1.10384461\n",
      "  0.78896131 0.60979315 0.39121348 0.67869145 0.72009107 0.98562753\n",
      "  0.96349618 0.400679   0.68112899 0.43156621 1.05224209]\n",
      " [0.99890235 0.70010508 0.88951117 1.04070962 1.78902556 0.77315447\n",
      "  0.71301493 0.92736842 0.72425245 0.81719807 1.15660938 0.58309596\n",
      "  0.90853687 0.36218917 0.47658137 0.80528362 0.64732853 1.14200595\n",
      "  0.78507677 0.62237188 0.44128741 0.58736908 0.65635776 0.73868178\n",
      "  0.9396166  0.45371174 0.70654156 0.56006952 0.70953946]\n",
      " [0.66413311 0.63080612 0.81235903 1.23579738 0.77315447 1.932096\n",
      "  0.57422635 0.92783679 0.59651661 0.67870537 0.80956635 0.50655966\n",
      "  0.92523497 0.38139009 0.43457364 0.6903186  0.58157564 0.80664559\n",
      "  0.54177056 0.50672642 0.42583641 0.5708276  0.58621616 0.62326693\n",
      "  0.70656875 0.47564428 0.57628063 0.36149511 1.28443402]\n",
      " [0.68002487 0.56872139 0.71613388 0.68846207 0.71301493 0.57422635\n",
      "  1.35048191 0.77289139 0.58578463 0.57403111 0.72263063 0.39298643\n",
      "  0.71657743 0.3017284  0.36846253 0.55643828 0.46561062 0.67219088\n",
      "  0.66536599 0.47665498 0.36173875 0.49229329 0.55685825 0.5388492\n",
      "  0.67278109 0.41338199 0.63107721 0.40505355 0.56518704]\n",
      " [0.9540385  1.06463549 1.06553088 1.32135157 0.92736842 0.92783679\n",
      "  0.77289139 2.1138036  0.79525    0.80262739 1.00421204 0.5480571\n",
      "  1.55356454 0.30302496 0.46719648 0.84032034 0.70486405 1.02298914\n",
      "  0.7633673  0.62992167 0.3658698  0.77258711 0.81982371 0.82657363\n",
      "  1.00074604 0.40619105 0.81891634 0.41893615 0.80896708]\n",
      " [0.72630968 0.65826615 0.7474291  0.79609702 0.72425245 0.59651661\n",
      "  0.58578463 0.79525    1.3897185  0.61904803 0.74277819 0.46273836\n",
      "  0.75294425 0.34308617 0.47212001 0.64962548 0.4866731  0.78442675\n",
      "  0.81991843 0.5270469  0.38869254 0.54309905 0.65908572 0.59748122\n",
      "  0.79335092 0.40774674 0.6886112  0.55004085 0.51060107]\n",
      " [0.70945859 0.66251941 0.77691868 0.88512353 0.81719807 0.67870537\n",
      "  0.57403111 0.80262739 0.61904803 1.63226569 0.84349145 0.46439182\n",
      "  0.76717143 0.37157516 0.39096364 0.65073111 0.57614062 0.87286369\n",
      "  0.59226376 0.51273082 0.42835501 0.5309683  0.56366909 0.72098388\n",
      "  0.75236424 0.4445684  0.53380786 0.42994184 0.62132567]\n",
      " [1.07333017 0.73789772 0.96595019 1.15246617 1.15660938 0.80956635\n",
      "  0.72263063 1.00421204 0.74277819 0.84349145 2.5195914  0.55940497\n",
      "  0.92434812 0.39589367 0.44534822 0.86494966 0.64920211 1.33841005\n",
      "  0.74573698 0.64343442 0.44494161 0.61596263 0.71733199 0.76577121\n",
      "  0.94849863 0.45110502 0.7420937  0.45376612 0.74855107]\n",
      " [0.48572094 0.47196466 0.56720978 0.53207219 0.58309596 0.50655966\n",
      "  0.39298643 0.5480571  0.46273836 0.46439182 0.55940497 1.00141421\n",
      "  0.54407322 0.37413977 0.42465458 0.59482171 0.64932007 0.58741227\n",
      "  0.47386734 0.59794565 0.42766657 0.4613535  0.55089357 0.47737998\n",
      "  0.54672332 0.42971094 0.57914349 0.40038253 0.5033388 ]\n",
      " [0.8251006  1.00101545 0.97737004 1.16862013 0.90853687 0.92523497\n",
      "  0.71657743 1.55356454 0.75294425 0.76717143 0.92434812 0.54407322\n",
      "  1.70226421 0.32373671 0.4832029  0.7922617  0.67528448 0.92505458\n",
      "  0.72935902 0.63717426 0.36924885 0.78505295 0.76115789 0.7564726\n",
      "  0.88179126 0.42799605 0.71716322 0.429858   0.79929981]\n",
      " [0.30601011 0.30743029 0.38099252 0.3575928  0.36218917 0.38139009\n",
      "  0.3017284  0.30302496 0.34308617 0.37157516 0.39589367 0.37413977\n",
      "  0.32373671 0.80620631 0.36013003 0.40569467 0.3838862  0.43059045\n",
      "  0.36992108 0.29980306 0.47161157 0.41169434 0.30970825 0.34156821\n",
      "  0.3566923  0.3967689  0.35538981 0.34610452 0.34374569]\n",
      " [0.45823283 0.35037656 0.47170257 0.45532119 0.47658137 0.43457364\n",
      "  0.36846253 0.46719648 0.47212001 0.39096364 0.44534822 0.42465458\n",
      "  0.4832029  0.36013003 1.08645862 0.42034437 0.40168401 0.57180894\n",
      "  0.45589715 0.34922409 0.36113169 0.42965168 0.43029041 0.36170601\n",
      "  0.49314053 0.35738508 0.43294896 0.37945512 0.38461827]\n",
      " [0.73218    0.65268493 0.87223471 1.06821468 0.80528362 0.6903186\n",
      "  0.55643828 0.84032034 0.64962548 0.65073111 0.86494966 0.59482171\n",
      "  0.7922617  0.40569467 0.42034437 1.23949227 0.58756374 0.82671503\n",
      "  0.64157778 0.55172153 0.41912491 0.62094738 0.62246677 0.74508991\n",
      "  0.74666898 0.40804632 0.62544734 0.42671961 0.64933174]\n",
      " [0.53433977 0.55568077 0.57833707 0.61626811 0.64732853 0.58157564\n",
      "  0.46561062 0.70486405 0.4866731  0.57614062 0.64920211 0.64932007\n",
      "  0.67528448 0.3838862  0.40168401 0.58756374 1.5043898  0.63257047\n",
      "  0.51638898 0.79082276 0.41487843 0.48436208 0.61451124 0.47522323\n",
      "  0.6132868  0.48144284 0.64004378 0.45948971 0.56611981]\n",
      " [1.22660419 0.7945144  0.92506778 1.10384461 1.14200595 0.80664559\n",
      "  0.67219088 1.02298914 0.78442675 0.87286369 1.33841005 0.58741227\n",
      "  0.92505458 0.43059045 0.57180894 0.82671503 0.63257047 2.12289303\n",
      "  0.84515648 0.65477087 0.4918338  0.62489805 0.81476537 0.76295069\n",
      "  1.17480747 0.45864529 0.83234273 0.4839239  0.66480043]\n",
      " [0.77524223 0.68112631 0.8218734  0.78896131 0.78507677 0.54177056\n",
      "  0.66536599 0.7633673  0.81991843 0.59226376 0.74573698 0.47386734\n",
      "  0.72935902 0.36992108 0.45589715 0.64157778 0.51638898 0.84515648\n",
      "  2.2110946  0.49981829 0.3854958  0.51341632 0.66458782 0.59963521\n",
      "  0.83936583 0.36567803 0.68944143 0.51048011 0.49289368]\n",
      " [0.5444771  0.54156063 0.53242063 0.60979315 0.62237188 0.50672642\n",
      "  0.47665498 0.62992167 0.5270469  0.51273082 0.64343442 0.59794565\n",
      "  0.63717426 0.29980306 0.34922409 0.55172153 0.79082276 0.65477087\n",
      "  0.49981829 1.22879713 0.36723356 0.4610153  0.6697631  0.50914121\n",
      "  0.60315567 0.38318442 0.64267657 0.42400373 0.50641961]\n",
      " [0.41917661 0.34473927 0.41390469 0.39121348 0.44128741 0.42583641\n",
      "  0.36173875 0.3658698  0.38869254 0.42835501 0.44494161 0.42766657\n",
      "  0.36924885 0.47161157 0.36113169 0.41912491 0.41487843 0.4918338\n",
      "  0.3854958  0.36723356 0.89602256 0.39177289 0.36013677 0.37091905\n",
      "  0.41507424 0.41455209 0.43448343 0.41645975 0.40484976]\n",
      " [0.50943202 0.53506318 0.62206326 0.67869145 0.58736908 0.5708276\n",
      "  0.49229329 0.77258711 0.54309905 0.5309683  0.61596263 0.4613535\n",
      "  0.78505295 0.41169434 0.42965168 0.62094738 0.48436208 0.62489805\n",
      "  0.51341632 0.4610153  0.39177289 1.05609328 0.57490249 0.5598936\n",
      "  0.5672914  0.42760787 0.55136283 0.38799285 0.51716774]\n",
      " [0.77433417 0.71830933 0.74452648 0.72009107 0.65635776 0.58621616\n",
      "  0.55685825 0.81982371 0.65908572 0.56366909 0.71733199 0.55089357\n",
      "  0.76115789 0.30970825 0.43029041 0.62246677 0.61451124 0.81476537\n",
      "  0.66458782 0.6697631  0.36013677 0.57490249 1.72193806 0.59735461\n",
      "  0.74636076 0.35659433 0.78012842 0.48215088 0.53046732]\n",
      " [0.69274799 0.67723734 0.93342475 0.98562753 0.73868178 0.62326693\n",
      "  0.5388492  0.82657363 0.59748122 0.72098388 0.76577121 0.47737998\n",
      "  0.7564726  0.34156821 0.36170601 0.74508991 0.47522323 0.76295069\n",
      "  0.59963521 0.50914121 0.37091905 0.5598936  0.59735461 1.30072769\n",
      "  0.73576514 0.37269622 0.62108866 0.44736971 0.57223138]\n",
      " [1.0086701  0.84700893 0.92483951 0.96349618 0.9396166  0.70656875\n",
      "  0.67278109 1.00074604 0.79335092 0.75236424 0.94849863 0.54672332\n",
      "  0.88179126 0.3566923  0.49314053 0.74666898 0.6132868  1.17480747\n",
      "  0.83936583 0.60315567 0.41507424 0.5672914  0.74636076 0.73576514\n",
      "  1.70685388 0.33726478 0.72017945 0.42402111 0.62643838]\n",
      " [0.29354661 0.34247718 0.42031728 0.400679   0.45371174 0.47564428\n",
      "  0.41338199 0.40619105 0.40774674 0.4445684  0.45110502 0.42971094\n",
      "  0.42799605 0.3967689  0.35738508 0.40804632 0.48144284 0.45864529\n",
      "  0.36567803 0.38318442 0.41455209 0.42760787 0.35659433 0.37269622\n",
      "  0.33726478 1.15714096 0.48910367 0.41384225 0.41153949]\n",
      " [0.69735896 0.66688086 0.67937008 0.68112899 0.70654156 0.57628063\n",
      "  0.63107721 0.81891634 0.6886112  0.53380786 0.7420937  0.57914349\n",
      "  0.71716322 0.35538981 0.43294896 0.62544734 0.64004378 0.83234273\n",
      "  0.68944143 0.64267657 0.43448343 0.55136283 0.78012842 0.62108866\n",
      "  0.72017945 0.48910367 2.55412679 0.62471282 0.50655322]\n",
      " [0.44587945 0.37953128 0.50859443 0.43156621 0.56006952 0.36149511\n",
      "  0.40505355 0.41893615 0.55004085 0.42994184 0.45376612 0.40038253\n",
      "  0.429858   0.34610452 0.37945512 0.42671961 0.45948971 0.4839239\n",
      "  0.51048011 0.42400373 0.41645975 0.38799285 0.48215088 0.44736971\n",
      "  0.42402111 0.41384225 0.62471282 1.50880951 0.36486707]\n",
      " [0.63272823 0.52158702 0.72979658 1.05224209 0.70953946 1.28443402\n",
      "  0.56518704 0.80896708 0.51060107 0.62132567 0.74855107 0.5033388\n",
      "  0.79929981 0.34374569 0.38461827 0.64933174 0.56611981 0.66480043\n",
      "  0.49289368 0.50641961 0.40484976 0.51716774 0.53046732 0.57223138\n",
      "  0.62643838 0.41153949 0.50655322 0.36486707 1.41401567]]\n"
     ]
    }
   ],
   "source": [
    "#compute mean returns and variance covariance matrix of returns\n",
    "meanReturns = np.mean(stockReturns, axis = 0)\n",
    "print('Mean returns of Dow Stocks:\\n',  meanReturns)\n",
    "covReturns = np.cov(stockReturns, rowvar=False)\n",
    "print('Variance-covariance matrix of returns of Dow Stocks:\\n')\n",
    "print(covReturns)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.5 Beta "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It is a fact that stocks which deliver high returns are prone to high risk. **Beta** $(\\beta)$  or **Beta coefficient**, also referred to as **financial elasticity** helps to determine the asset risk with regard to that of the markets. Beta measures the volatility or systematic risk of an investment and is computed as, "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Eqn1_2.png)\n",
    "<h5 align=\"right\">..........(1.2)</h5>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where $cov(r_i, r_P)$ is the covariance of the rate of return $r_i$  of the asset $i$ in a portfolio P and $r_P$,  the rate of return of the portfolio P. $var(r_P)$ is the variance of the rate of return $r_P$ of the portfolio P. In practice, the portfolio return $r_P$ is replaced by the market index return that was explained in Sec. 1.3.\n",
    "\n",
    "The interpretation of  $\\beta$ is as follows:\n",
    "$\\beta=0$ implies that the stock return is uncorrelated with the market movements,\n",
    "$\\beta <0$ implies that the stock return inversely follows the market movements, and\n",
    "$\\beta >0$ implies that the stock return follows the market movements.  \n",
    "For the last case, if $\\beta <1$, then the stock is less volatile than the market, if $\\beta>1$, then the stock is more volatile than the market and if $\\beta =1$, then the stock is as volatile as the market. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us suppose an investor decides to hold a **portfolio P** of the following 15 Dow stocks:\n",
    "'AAPL', 'AXP', 'BA', 'CAT', 'CSCO', 'DIS', 'GS', 'HD', 'IBM', 'JPM', 'KO', 'MCD', 'MRK', 'UNH', 'WBA'. The investor wishes to investigate the volatilities of the assets and therefore computes the individual asset betas over a 3-Year market data ( April 2016 -April 2019). The Python code to compute asset betas is shown below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Portfolio stocks\n",
      " ['AAPL', 'AXP', 'BA', 'CAT', 'CSCO', 'DIS', 'GS', 'HD', 'IBM', 'JPM', 'KO', 'MCD', 'MRK', 'UNH', 'WBA']\n",
      "Asset Betas:  \n",
      "\n",
      "    1.134\n",
      "    1.087\n",
      "    1.392\n",
      "    1.527\n",
      "    1.154\n",
      "    0.767\n",
      "    1.317\n",
      "    0.937\n",
      "    0.976\n",
      "    1.115\n",
      "    0.460\n",
      "    0.554\n",
      "    0.735\n",
      "    0.950\n",
      "    0.850\n"
     ]
    }
   ],
   "source": [
    "#compute betas of Dow stocks over a 3-year historical period,\n",
    "#DJIA Index- April 2016 to April 2019\n",
    "\n",
    "#dependencies\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "#input stock prices and market datasets\n",
    "stockFileName = 'DJIAkpf1Apr2016to20193YBeta.csv'\n",
    "marketFileName = 'DJIAMarketDataApr2016to20193YBeta.csv'\n",
    "stockRows = 756  #excluding header \n",
    "stockColumns = 15  #excluding date\n",
    "marketRows = 756\n",
    "marketColumns = 7\n",
    "\n",
    "#read stock prices dataset and market dataset \n",
    "dfStock = pd.read_csv(stockFileName,  nrows= stockRows)\n",
    "dfMarket = pd.read_csv(marketFileName, nrows = marketRows)\n",
    "\n",
    "#extract asset labels of stocks in the portfolio\n",
    "assetLabels = dfStock.columns[1:stockColumns+1].tolist()\n",
    "print('Portfolio stocks\\n', assetLabels)\n",
    "\n",
    "#extract asset prices data and market data\n",
    "stockData = dfStock.iloc[0:, 1:]\n",
    "marketData = dfMarket.iloc[0:, [4]] #closing price \n",
    "\n",
    "#compute asset returns\n",
    "arrayStockData = np.asarray(stockData)\n",
    "[sRows, sCols]=arrayStockData.shape\n",
    "stockReturns = StockReturnsComputing(arrayStockData, sRows, sCols)\n",
    "\n",
    "#compute market returns\n",
    "arrayMarketData = np.asarray(marketData)\n",
    "[mRows, mCols]=arrayMarketData.shape\n",
    "marketReturns = StockReturnsComputing(arrayMarketData, mRows, mCols)\n",
    "\n",
    "#compute betas of assets in the portfolio\n",
    "beta= []\n",
    "Var = np.var(marketReturns, ddof =1)\n",
    "for i in range(stockColumns):\n",
    "    CovarMat = np.cov(marketReturns[:,0], stockReturns[:, i ])\n",
    "    Covar  = CovarMat[1,0]\n",
    "    beta.append(Covar/Var)\n",
    "    \n",
    "    \n",
    "#output betas of assets in the portfolio\n",
    "print('Asset Betas:  \\n')\n",
    "for data in beta:\n",
    "    print('{:9.3f}'.format(data))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A careful observation of the betas of the Dow stocks reveal that AAPL, AXP, BA, CAT, CSCO, GS and JPM, whose betas are greater than 1, are notionally more volatile than the market, while the rest of the stocks in the portfolio whose betas are less than 1 ( but > 0), are notionally less volatile than the market. A stock with beta equal to 1, moves with the market. Thus, IBM and UNH could be viewed as moving with the market. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.6   Portfolio weights and Portfolio Beta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The amount of capital invested in  assets comprising a portfolio,  by the investor is termed **weights**. Portfolio weights therefore indicate the proportion of investments made over the assets comprising the portfolio. Though portfolio weights are practically expressed as a percentage, it is convenient to express them as lying in the interval [0-1], where 0 weights indicate nil investment in the asset and 1 indicates full investment of capital in an asset. An interval (0,1], would mean that every asset in the portfolio must have some portion of the capital invested in it.  A portfolio whose weights sum up to 1, is called a *fully invested portfolio* and a portfolio whose weights are equally distributed   is called as *equal weighted portfolio*.  \n",
    "\n",
    "With regard to portfolios with equity stocks, **portfolio beta** is the weighted sum of the asset betas,where the weights are represented by the portfolio weights. Portfolio beta is given by, $\\sum{\\beta_i.W_i}$, where $\\beta_i$ are the asset betas and $W_i$ are the portfolio weights. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.7   Portfolio Return and Portfolio Risk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Harry Markowtiz [MAR 52] proposed a framework known as **Mean-Variance Analysis** which won him the 1990 Nobel Prize in Economics. The framework laid the foundation for what is known as **Modern Portfolio Theory**. It viewed **portfolio return** as the capital gain that can be expected by holding a portfolio and **portfolio risk** as the extent of capital losses that it can suffer possibly due to adverse market movements. Portfolio return and risk were modelled using the *mean* and *variance* of the portfolio's fluctuations respectively. \n",
    "\n",
    "Portfolio return is  defined as follows:\n",
    "Let P be a portfolio comprising assets $A_1, A_2,...A_N$ with weights $W_1, W_2,...W_N$ and $r_1, r_2, ...r_N$ as the asset returns. The portfolio return *r*  determined by a weighted summation of its individual asset returns is given by, "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Eqn1_3.png)\n",
    "<h5 align=\"right\">..........(1.3)</h5>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The **annualized portfolio return** assuming that the number of trading days in a year were $T_y$ ( for example, 261 out of 365 days in a year), is given by,"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Eqn1_4.png)\n",
    "<h5 align=\"right\">..........(1.4)</h5>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Portfolio risk is the standard deviation of its returns and is given by,"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Eqn1_5.png)\n",
    "<h5 align=\"right\">..........(1.5)</h5>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where $\\sigma_{ij}$ is the covariance of returns between assets i and j of the portfolio, also referred to as the variance-covariance matrix of returns. Standard deviation is a prominent measure of dispersion of data borrowed from Statistics and describes the deviation or spread of the data from its mean. In the case of portfolios, standard deviation of its returns, which is its risk, helps to measure the consistency of the returns. \n",
    "The **annualized portfolio risk** in percentage,  $\\sigma_{Ann}$ is given by,"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Eqn1_6.png)\n",
    "<h5 align=\"right\">..........(1.6)</h5>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where $T_y$ is the number of trading days in a year."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 align=\"left\">Risk-Return Tradeoff</h3>  \n",
    "\n",
    "It is an established trading principle that investments giving high returns are always associated with a probability of high risks and those that are less risky are associated with a probability of low returns. A typical example is when an investor facing retirement from service,  chooses to invest her hard-earned retirement benefits  in bank deposits or government bonds which are risk free (and therefore yield low returns), rather than investing them in stock markets which despite their  potential to yield massive returns are bound by risks. Again, time plays a significant role while managing the risk - reward interplay of investments. For example,  a long term investment in high yielding stocks in the stock market or real estate, can help appreciation of the investor's capital, while offering the potential to recover from risks. The risk-return tradeoff therefore,  rests on many factors such as investor's risk appetite, holding period of securities and the potential to make up for losses. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 align=\"left\">1.8  Case Study</h2>  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us consider the portfolio P of Dow stocks described in Sec. 1.5. Let us suppose that a moderately risk-averse investor having realized the volatility of stocks after computing the asset betas, decides to invest 40% of  the capital in stocks with high volatility ($\\beta >1$) and 60% of the capital on other stocks which are less volatile or will move with the market ($\\beta \\le 1$). The portfolio weights reflecting the same are shown in the table. The red banded tickers indicate high volatility stocks, the green banded tickers indicate low volatility stocks and blue banded stocks indicate those that will move with the market.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Thus, if the investor owns a capital of USD 10,000, the investor decides to invest  USD 6000 on less risky  stocks and USD 4000 on risky stocks. The apportioning of the capital between  individual stocks are determined by the weights, which let us suppose the investor chose to do it according to her own whims and fancies! Thus,stocks  AAPL, AXP, BA, CAT, CSCO, GS and JPM, which are highly volatile are allotted  9%,  7%, 3%, 2%, 7%, 4% and 8% of the capital respectively,  that adds up to USD 4000. Stocks DIS, HD, IBM, KO, MCD, MRK, UNH and  WBA are allotted 6%,7%, 11%, 9%, 7%, 5%, 11% and 4% respectively,  that adds up to USD 6000. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1Fig1_3.png)\n",
    "<h4 align=\"center\">Fig. 1.3 Asset betas and portfolio weights of 15 Dow stocks held by an investor for Portfolio P</h4>  \n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "  \n",
    "The Python code fragment to compute the portfolio return and risk is given below. The portfolio weights and asset betas have been provided as direct inputs in the code to aid  brevity of presentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Annualized Portfolio Risk: 12.54 %\n",
      "\n",
      " Annualized Expected Portfolio Return: 14.94 %\n",
      "\n",
      " Portfolio Beta:0.95\n"
     ]
    }
   ],
   "source": [
    "#portfolio risk, expected return and portfolio beta computation\n",
    "\n",
    "#input weights and asset betas for portfolio P as described in Sec. 1.5\n",
    "weights = np.array([0.09, 0.07, 0.03, 0.02, 0.07, 0.06, 0.04, 0.07, 0.11, \\\n",
    "                    0.08, 0.09, 0.07, 0.05, 0.11, 0.04])\n",
    "assetBeta = np.array([1.13, 1.09, 1.39, 1.53, 1.15, 0.77, 1.32, 0.94, 0.98,\\\n",
    "                      1.12, 0.46, 0.55, 0.74, 0.95, 0.85])\n",
    "\n",
    "#compute mean and covariance of asset returns of portfolio P available in stockReturns\n",
    "meanReturns = np.mean(stockReturns, axis = 0)\n",
    "covReturns = np.cov(stockReturns, rowvar=False)\n",
    "\n",
    "#compute portfolio risk\n",
    "portfolioRisk = np.matmul((np.matmul(weights,covReturns)), np.transpose(weights))\n",
    "\n",
    "#compute annualized portfolio risk for trading days = 251\n",
    "annualizedRisk  =   np.sqrt(portfolioRisk*251) \n",
    "\n",
    "#compute expected portfolio return\n",
    "portfolioReturn = np.matmul(np.array(meanReturns),weights.T)\n",
    "\n",
    "#compute annualized expected portfolio return\n",
    "annualizedReturn = 251*np.array(portfolioReturn) \n",
    "\n",
    "#compute portfolio beta\n",
    "portfolioBeta = np.matmul(assetBeta,weights.T)\n",
    "\n",
    "#display results\n",
    "print(\"\\n Annualized Portfolio Risk: %4.2f\" % annualizedRisk,\"%\")\n",
    "print(\"\\n Annualized Expected Portfolio Return: %4.2f\" % annualizedReturn,\"%\")\n",
    "print(\"\\n Portfolio Beta:%4.2f\" % portfolioBeta)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " <h3 align=\"left\">Investment analysis of Portfolio P</h3>  \n",
    "\n",
    "The risk-averse investor was playing moderately safe by investing only 40% of the capital in stocks with high volatility and 60% in stocks with less volatility. The portfolio yields an annual expected return of 14.94%. If one were to compare the returns with those of 10-year Treasury Bond (T-Bonds) issued by the US Government which are fixed interest debt securities that are risk-free (investors receive fixed interest payments until maturity date), the average annual return of T-Bonds for the period 2014 - 2018 was 3.1%, with a high of 10.75% during 2014. Again, comparing the returns of the portfolio with that of the Dow Jones Industrial Average market index, the average annual rate of return has been 5.42%.  Thus, in this specific case, portfolio P was able to beat the market!  \n",
    "\n",
    "  \n",
    "However, the annualized risk of 12.54% needs to be seriously looked at. As explained earlier,  the risk is a measure of the consistency of the return. If the investor's risk appetite can accommodate this, then all is well!  \n",
    "Happy investing!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 align=\"left\">Companion Reading</h2>  \n",
    "\n",
    "This blog  is an abridged adaptation of concepts discussed in Chapter 1 of [PAI 18] to Dow Jones dataset (DJIA index: April, 2014- April, 2019) and implemented in Python. Readers (read \"worker bees\"),  seeking more information may refer to the corresponding chapter in the  book.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2 align=\"left\">References</h2>\n",
    "\n",
    "[MAR 52]   Markowitz H., Portfolio Selection, *The Journal of Finance*, vol. 7, no. 1, \n",
    "           pp. 77-91, Mar., 1952.\n",
    "\n",
    "[PAI 18]   Vijayalakshmi Pai G. A., Metaheuristics for Portfolio Optimization- *An \n",
    "           Introduction using MATLAB*, Wiley-ISTE, 2018. https://www.mathworks.com/academia/books/metaheuristics-for-portfolio-optimization-pai.html"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Next .....Lesson2:  Some Glimpses of Financial Data Wrangling \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](Lesson1ExitTailImage.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<style\n",
    "  type=\"text/css\">\n",
    "h1 {color:red;}\n",
    "\n",
    "p {color:blue;}\n",
    "</style>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<style\n",
    "  type=\"text/css\">\n",
    "h1 {color:red;}\n",
    "\n",
    "p {color:blue;}\n",
    "</style>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
